package com.yhh;

import com.yhh.Entity.Command;
import com.yhh.Entity.HandlerCommand;
import com.yhh.Exceptions.InstructionException;
import com.yhh.Exceptions.LocalCommandException;
import com.yhh.Exceptions.NonInstructionException;

import java.net.Socket;
import java.util.Map;

class ClearCommand extends Command implements HandlerCommand {
    private static final String c = "clear";

    protected ClearCommand(Socket socket) {
        super(socket);
        command.add("-m");
        command.add("-a");
    }

    @Override
    public void handlerParameter(Map<String, String> args) throws InstructionException, NonInstructionException {
        if (args.get("-m") != null) {
            String m = args.get("-m");
            if (m.length() != 10) throw new InstructionException("-m参数有误", c);
        }
    }

    @Override
    public boolean check(Map<String, String> args) throws NonInstructionException, InstructionException {
        checkParameter(args);
        handlerParameter(args);
        return true;
    }

    @Override
    public void handlerCommand(Map<String, String> args) throws InstructionException, NonInstructionException, LocalCommandException {
        String resp = recvMsg();
        System.out.println(resp);
    }
}
